package com.snoweagler.verify;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.snoweagler.VO.ResponseVO;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class AuthentionSuccessFilter implements AuthenticationSuccessHandler {

    @Resource
    ObjectMapper objectMapper;
    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType(MediaType.APPLICATION_JSON_UTF8.toString());
        response.getWriter().write(objectMapper.writeValueAsString(ResponseVO.ok()));
    }
}
